package com.hbm.usercenter.fragment;


import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.AbsListView;
import android.widget.ListView;

import com.hbm.usercenter.base.BaseFragment;
import com.hbm.usercenter.base.BaseHolder;
import com.hbm.usercenter.base.LoadingPager;
import com.hbm.usercenter.base.LoadingPager.LoadedResult;
import com.hbm.usercenter.base.SuperBaseAdapter;
import com.hbm.usercenter.bean.GroupOrderBean;
import com.hbm.usercenter.factory.ListViewFactory;
import com.hbm.usercenter.holder.GroupOrderHolder;
import com.hbm.usercenter.protocol.ListApplyProtocol;
import com.hbm.usercenter.utils.LogUtils;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class ListApplyFragment extends BaseFragment {

//
//    public ListApplyFragment() {
//        // Required empty public constructor
//    }
//
//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//                             Bundle savedInstanceState) {
//        // Inflate the layout for this fragment
//        return inflater.inflate(R.layout.fragment_list_apply, container, false);
//    }
protected ListApplyProtocol mProtocol;
    protected List<GroupOrderBean.MyCheckBean> mDatas;
    @Override
    protected LoadingPager.LoadedResult initData() {
        mProtocol = new ListApplyProtocol();
        try {
            GroupOrderBean groupOrderBean = mProtocol.loadData(0);
            LogUtils.s("ListApplyFragment----" + groupOrderBean.toString());
            LoadedResult checkState = checkState(groupOrderBean);
            if (checkState != LoadedResult.SUCCESS) {
                return checkState;
            }
            checkState = checkState(groupOrderBean.mycheckList);
            if (checkState != LoadedResult.SUCCESS) {
                return checkState;
            }
            mDatas = groupOrderBean.mycheckList;

            return LoadedResult.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return LoadedResult.ERROR;
        }
    }

    @Override
    protected View initSuccessView() {
        ListView listView = ListViewFactory.createListView();
        listView.setAdapter(new ApplyAdapter(listView, mDatas));
        return listView;
    }
    class ApplyAdapter extends SuperBaseAdapter<GroupOrderBean.MyCheckBean> {

        public ApplyAdapter(AbsListView absListView, List<GroupOrderBean.MyCheckBean> datas) {
            super(absListView, datas);
        }

        @Override
        protected BaseHolder<GroupOrderBean.MyCheckBean> getSpecialHolder(int position) {
            return new GroupOrderHolder();
        }
    }
}
